#coding:utf-8
import re,logging,os
from google.appengine.ext import db

class Categories(db.Model):
    name = db.StringProperty(required=True)
    description = db.StringProperty()

class Files(db.Model):
    name = db.StringProperty(required=True)
    mime = db.StringProperty(required=True)
    size = db.IntegerProperty(required=True)
    created_at = db.DateTimeProperty(auto_now_add=True)
    category = db.ReferenceProperty(Categories)
    isimage = db.IntegerProperty()
    bf = db.BlobProperty() #binary file

    def delete(self):
        super(Files,self).delete()

    def put(self):
        super(Files,self).put()
            
    @property
    def id(self):
        return str(self.key().id())
    
    @property
    def downurl(self):
        return "http://%s/file/down/%s/%s" %(os.environ['HTTP_HOST'], self.key().id(), self.name)

    @property
    def showurl(self):
        return "http://%s/file/show/%s/%s" %(os.environ['HTTP_HOST'], self.key().id(), self.name)
